package dormouse.bookmarks.linux;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;

import dormouse.bookmarks.Bookmark;
import dormouse.bookmarks.IBookmarkWriter;

/**
 * Implements Linux bookmark files which are in the following format:
 * 
 * <code>
 * [Desktop Entry]
 * Version=1.0
 * Encoding=UTF-8
 * Name=Link to From Java Platform Improvements to Better Teaching: A Conversation With Java Champion Cay Horstmann
 * Type=Link
 * URL=http://java.sun.com/developer/technicalArticles/Interviews/community/horstmann_qa.html
 * Icon=gnome-fs-bookmark
 * 
 * </code>
 */
public class LinuxBookmarkWriter implements IBookmarkWriter {

    public void writeBookMark(String outputURL, Bookmark bookmark) throws IOException {
        FileSystemManager mgr = VFS.getManager();
        FileObject file = mgr.resolveFile(outputURL);

        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(file.getContent().getOutputStream()));
        out.write("[Desktop Entry]\nVersion=1.0\nEncoding=UTF-8");
        out.write("Name=" + bookmark.getName());
        out.write("Type=Link\n");
        out.write("URL=" + bookmark.getUrl());
        out.write("Icon=gnome-fs-bookmark");
        out.flush();
        out.close();
    
    }


    

}
